package com.two.screen.water.balance.ui.fragment

import android.annotation.SuppressLint
import android.os.Bundle
import android.widget.TextView
import butterknife.BindView
import com.two.screen.water.balance.R
import com.two.screen.water.balance.ui.fragment.base.BaseFragment
import com.two.screen.water.balance.utils.CommUtils
import com.two.screen.water.balance.widget.dialog.AssociateDetailDialog
import com.two.screen.water.balance.widget.dialog.ChooseDateDialog
import com.two.screen.water.balance.widget.dialog.SaleGoodsReportDialog

@SuppressLint("NonConstantResourceId")
class AssociateFragment() : BaseFragment() {
    override fun setLayoutResouceId(): Int = R.layout.fragment_associate

    @BindView(R.id.mDetailTv) protected lateinit var mDetailTv: TextView
    @BindView(R.id.mSaleGoodsReportTv) protected lateinit var mSaleGoodsReportTv: TextView
    @BindView(R.id.mAssociateQuitTv) protected lateinit var mAssociateQuitTv: TextView
    @BindView(R.id.mLineValue01Tv) protected lateinit var mLineValue01Tv: TextView
    @BindView(R.id.mLineValue02Tv) protected lateinit var mLineValue02Tv: TextView
    @BindView(R.id.mLineValue03Tv) protected lateinit var mLineValue03Tv: TextView
    @BindView(R.id.mLineValue04Tv) protected lateinit var mLineValue04Tv: TextView
    @BindView(R.id.mCashierOnlineTimeTv) protected lateinit var mCashierOnlineTimeTv: TextView
    @BindView(R.id.mCashierNameTv) protected lateinit var mCashierNameTv: TextView
    @BindView(R.id.mStartTimeTv) protected lateinit var mStartTimeTv: TextView
    @BindView(R.id.mEndTimeTv) protected lateinit var mEndTimeTv: TextView


    var mAssociateDetailDialog: AssociateDetailDialog? = null
    var mSaleGoodsReportDialog: SaleGoodsReportDialog? = null

    var mChooseDateDialog: ChooseDateDialog? = null
    private var mDateBegin: String? = null
    private var mDateEnd: String? = null


    override fun initView() {
    }

    override fun initData(arguments: Bundle?) {
        initChooseDate()
    }

    @SuppressLint("CheckResult")
    private fun initChooseDate() {
        //筛选日期
        mDateBegin = CommUtils.toYMD(System.currentTimeMillis() / 1000 /*- 8 * 24 * 3600*/)
        mDateEnd = CommUtils.toYMD(System.currentTimeMillis() / 1000)
        mStartTimeTv?.text = mDateBegin
        mEndTimeTv?.text = mDateEnd
        mStartTimeTv?.setOnClickListener { showChooseDate() }
        mEndTimeTv?.setOnClickListener { showChooseDate() }
    }

    private fun showChooseDate() {
        if (mChooseDateDialog == null) mChooseDateDialog = ChooseDateDialog(mActivity)
        mChooseDateDialog?.setOnChooseDateDialogListener(object : ChooseDateDialog.OnChooseDateDialogListener {
            override fun hadSelectedCalendar(mStartDateStr: String, mEndDateStr: String) {
                mStartTimeTv?.text = mStartDateStr
                mEndTimeTv?.text = mEndDateStr
                mDateBegin = mStartDateStr
                mDateEnd = mEndDateStr
            }
        })
        mChooseDateDialog?.show()
    }

    override fun setOnLazyLoad(): Boolean = true
    override fun onLazyLoad() {

    }

    override fun initListener() {
        mDetailTv.setOnClickListener {
            if (mAssociateDetailDialog == null) mAssociateDetailDialog = AssociateDetailDialog(context!!)
            mAssociateDetailDialog?.show()
        }

        mSaleGoodsReportTv.setOnClickListener {
            if (mSaleGoodsReportDialog == null) mSaleGoodsReportDialog = SaleGoodsReportDialog(context!!)
            mSaleGoodsReportDialog?.show()
            mSaleGoodsReportDialog?.setDialogInfo(null)
        }
    }


}